<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">

    <script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <form action="" class="layui-form" lay-filter="residentForm">
            <input type="hidden" name="id" class="layui-input">

            <div class="layui-form-item">
                <label class="layui-form-label required">访客姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名"
                        value="" class="layui-input">

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">电话</label>
                <div class="layui-input-block">
                    <input type="text" name="tel" lay-verify="required" lay-reqtext="电话不能为空" placeholder="请输入电话"
                        value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">地址</label>
                <div class="layui-input-block">
                    <input type="text" name="address" lay-verify="required" lay-reqtext="地址不能为空" placeholder="请输入地址"
                        value="" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">风险地区</label>
                <div class="layui-input-block">
                    <input type="radio" name="isrisk" value="低风险地区" title="低风险地区" checked="">
                    <input type="radio" name="isrisk" value="中风险地区" title="中风险地区">
                    <input type="radio" name="isrisk" value="高风险地区" title="高风险地区">

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">来访时间</label>
                <div class="layui-input-block">
                    <input type="text" name="entertime" id="enter" lay-verify="date" placeholder="yyyy-MM-dd"
                        autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">离开时间</label>
                <div class="layui-input-block">
                    <input type="text" name="outtime" id="out" lay-verify="date" placeholder="yyyy-MM-dd"
                        autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>


        </form>
    </div>
    <script>
        layui.use(['form', 'upload', 'element'], function () {
            var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                element = layui.element,
                laydate = layui.laydate,//添加日期
                $ = layui.$;


            laydate.render({
                elem: '#enter'

            });
            laydate.render({
                elem: '#out'

            });

            //从localStorage 把数据取出来  赋值给表单项
            var jsonStr = localStorage.getItem("register");
            var stuObj = JSON.parse(jsonStr);
            console.log(stuObj)
            //给表单项赋值
            form.val("residentForm", {

                id: stuObj.id,
                name: stuObj.name,
                tel: stuObj.tel,
                address: stuObj.address,
                isrisk: stuObj.isrisk,
                entertime: stuObj.entertime,
                outtime: stuObj.outtime,

            })
            
            //监听提交
            form.on('submit(saveBtn)', function (data) {

                $.ajax({
                    url: "http://localhost:8080/register/updateRegister",
                    data: data.field,
                    type: "post",
                    success: function (result) {
                        if (result.code == 0) {

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改成功");
                            parent.layer.close(iframeIndex);
                            parent.reload;


                        } else {
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg("修改失败");
                            parent.layer.close(iframeIndex);
                        }
                    },
                    dataType: "json"
                })


                return false;
            });


        });
    </script>
</body>

</html>